package com.apimarket.controller;

import com.apimarket.dao.ProtocolMapper;
import com.apimarket.entity.Result;
import com.apimarket.util.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Author ZXR
 * @Date 2021/7/7 15:39
 * @Version 1.0
 */

@RequestMapping("protocol")
@RestController
public class ProtocolController {
    @Autowired
    private ProtocolMapper protocolMapper;
    @Value("${redis.protocol.type}")
    private String redisProType;
    @Autowired
    private RedisUtils redisUtils;
    @RequestMapping("findList")
    public Result<List<Map<String,Object>>> findList(){
        //先判断缓存中有没有
        List<Map<String,Object>> result= (List<Map<String, Object>>) redisUtils.judgeAndGet(redisProType);
        if(result==null){
            result=protocolMapper.findList();
            redisUtils.set(redisProType,result);
        }
        return new Result<>(result,200,"success");
    }
}
